package com.example.admin.service.impl;

import cn.hutool.crypto.digest.BCrypt;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.admin_model.entity.Employee;
import com.example.config.JwtConfig;
import com.example.admin.mapper.EmployeeMapper;
import com.example.admin.service.EmployeeService;
import com.example.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 员工信息 服务实现类
 * </p>
 *
 * @author sjz
 * @since 2024-06-26
 */
@Service
@Slf4j
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Resource
    private JwtConfig jwtConfig;


    @Override
    public String validate(String token) {

        log.info("token:{}",token);

        if(!JwtUtils.validateToken(token,jwtConfig.getKey())){
            throw new RuntimeException("token失效");
        }

        Claims claims = JwtUtils.parseJwt(token, jwtConfig.getKey());
        return claims.get("adminId", String.class);
    }


}
